#!/usr/bin/env python
# codeing=utf-8


import os,sys

cmd = r'protoc.exe -I="%s" --cpp_out="%s" --python_out="%s" "%s"'

def generate():
    curr = os.getcwd()
    cpp_out = os.path.join(curr,r'out\%s\cpp')
    py_out = os.path.join(curr,r'out\%s\python')
    files = os.listdir(curr)
    MKDIR = lambda d : not os.path.isdir(d) and os.mkdir(d)
    for f in files:
        if f.endswith(".proto"):
            MKDIR("out")
            MKDIR("./out/%s"%f[:-6])
            co = cpp_out%f[:-6]
            po = py_out%f[:-6]
            MKDIR(co)
            MKDIR(po)
            cmd_str = cmd % (curr,co,po, os.path.join(curr,f) )
            print cmd_str
            print os.system(cmd_str)


if __name__ == "__main__":
    generate()

